package net.chenyan.server.specs;/**
 * @author chenyan
 * @createTime 2022/4/26 16:51
 * @description description
 */

/**
 *@description: TODO
 *@author: chenyan
 *@create: 2022/4/26 16:51
 */


import java.io.Serializable;
import javax.persistence.EntityManager;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.support.JpaRepositoryFactory;
import org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean;
import org.springframework.data.repository.core.RepositoryMetadata;
import org.springframework.data.repository.core.support.RepositoryFactorySupport;

public class CustomRepositoryFactoryBean<T extends JpaRepository<S, ID>, S, ID extends Serializable>
        extends JpaRepositoryFactoryBean<T, S, ID>{

    public CustomRepositoryFactoryBean(Class<? extends T> repositoryInterface) {
        super(repositoryInterface);
    }

    @Override
    protected RepositoryFactorySupport createRepositoryFactory(EntityManager entityManager){
        return new CustomRepositoryFactory(entityManager);
    }

    private static class CustomRepositoryFactory extends JpaRepositoryFactory{
        public CustomRepositoryFactory(EntityManager entityManager){
            super(entityManager);
        }



    @Override
    protected Class<?> getRepositoryBaseClass(RepositoryMetadata metadata){
        return CustomRepositoryImpl.class;
    }
    }
}
